package com.tpi.smartpayments;

/**
 * <p>Title: SmartPaymentsClient_JavaHTTPPost</p>
 *
 * <p>Description: A simple example to show how to use HTTP POST to send
 * transactions to the SmartPayments Web Service</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: TPI Software</p>
 *
 * @author Andy Chau
 * @version 1.0
 */

public class SmartPayments extends Base{

    public SmartPayments() {
        url = "https://www.tpisoft.com/SmartPayments/Transact.asmx";
    }

    public SmartPayments(String url) {
        this.url = url;
    }

    /**
     * Process ePayment Credit Card Transaction. Valid input values are:
     * UserName & Password - Assigned by the payment gateway, <BR>TransType
     * - Auth | Sale | Return | Void | Force | Capture | RepeatSale | CaptureAll,
     * <BR>CardNum - Payment Card Number, ExpDate - Payment Card Expiration
     * Date in MMYY format, <BR>MagData - Payment Card Track II Mag-Stripe
     * Data, NameOnCard - Cardholders Name, Amount - Amount in DDDDD.CC format,
     * <BR>InvNum - Invoice Tracking Number, PNRef - Reference Number Assigned
     * by the payment gateway, <BR>Zip - CardHolder's billing ZipCode used
     * with AVS,  <BR>Street - CardHolder's billing Street Address used with
     * AVS,  <BR>CVNum - CardHolder's Card Verification Number used with
     * CV Check, <BR>ExtData - Extended Data in XML, Valid Values are: CustomerID<BR>AuthCode
     * - Original Authorization Code, <BR>CustCode - Customer Code used with
     * Commercial Cards, <BR>TipAmt - Tip Amount <BR>TaxAmt - Tax Amount
     * used with Commercial Cards, <BR>SequenceNum - Sequence Number used
     * with Recurring Transactions, <BR>SequenceCount - Sequene Count used
     * with Recurring Transactions, <BR>ServerID - Server ID, <BR>Timeout
     * - Timeout Value in Seconds (default=40), <BR>TrainingMode - Training
     * Mode T or F, <BR>Force - Force Duplicates T or F, <BR>RegisterNum
     * - Register Number, <BR>PONum - Purhcase Order Number, <BR>City - the
     * City of the CardHolder's billing address<BR>
     */
    synchronized public Response processCreditCard(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String CardNum, java.lang.String ExpDate, java.lang.String MagData, java.lang.String NameOnCard, java.lang.String Amount, java.lang.String InvNum, java.lang.String PNRef, java.lang.String Zip, java.lang.String Street, java.lang.String CVNum, java.lang.String ExtData) throws java.io.IOException {
       java.lang.StringBuffer sb = new StringBuffer();
       sb.append("UserName=" + urlEncode(UserName));
       sb.append("&Password=" + urlEncode(Password));
       sb.append("&TransType=" + urlEncode(TransType));
       sb.append("&CardNum=" + urlEncode(CardNum));
       sb.append("&ExpDate=" + urlEncode(ExpDate));
       sb.append("&MagData=" + urlEncode(MagData));
       sb.append("&NameOnCard=" + urlEncode(NameOnCard));
       sb.append("&Amount=" + urlEncode(Amount));
       sb.append("&InvNum=" + urlEncode(InvNum));
       sb.append("&PNRef=" + urlEncode(PNRef));
       sb.append("&Zip=" + urlEncode(Zip));
       sb.append("&Street=" + urlEncode(Street));
       sb.append("&CVNum=" + urlEncode(CVNum));
       sb.append("&ExtData=" + urlEncode(ExtData));
       String postData = sb.toString();
       String responseData = Util.sendHttpPost(url + "/ProcessCreditCard", postData, timeout, verbose);
       return new Response(responseData);
   }

/**
 * Process ePayment Debit Card Transactions. Valid input values are:
 * UserName & Password - Assigned by the payment gateway, <BR>TransType
 * - Auth | Sale | Return | Force | Capture |  CaptureAll, <BR>CardNum
 * - Payment Card Number, ExpDate - Payment Card Expiration Date in MMYY
 * format, <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard
 * - Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>Pin -
 * Pin Block Returned by Pin-Pad, <BR>RegisterNum - Register Number Pin-Pad
 * is Connected, <BR>SureChargeAmt - Sure Charge Amount in DDDDD.CC format,
 * <BR>CashBackAmt - Cash Back Amount in DDDDD.CC format, <BR>ExtData
 * - Extended Data in XML, Valid Values are: <BR>Timeout - Timeout Value
 * in Seconds (default=40), <BR>TrainingMode - Training Mode T or F,
 * <BR>KeySerialNumber - Key Serial Number for DUKPT<BR>
 */
synchronized public Response processDebitCard(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String CardNum, java.lang.String ExpDate, java.lang.String MagData, java.lang.String NameOnCard, java.lang.String Amount, java.lang.String InvNum, java.lang.String PNRef, java.lang.String Pin, java.lang.String RegisterNum, java.lang.String SureChargeAmt, java.lang.String CashBackAmt, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&TransType=" + urlEncode(TransType));
    sb.append("&CardNum=" + urlEncode(CardNum));
    sb.append("&ExpDate=" + urlEncode(ExpDate));
    sb.append("&MagData=" + urlEncode(MagData));
    sb.append("&NameOnCard=" + urlEncode(NameOnCard));
    sb.append("&Amount=" + urlEncode(Amount));
    sb.append("&InvNum=" + urlEncode(InvNum));
    sb.append("&PNRef=" + urlEncode(PNRef));
    sb.append("&Pin=" + urlEncode(Pin));
    sb.append("&RegisterNum=" + urlEncode(RegisterNum));
    sb.append("&SureChargeAmt=" + urlEncode(SureChargeAmt));
    sb.append("&CashBackAmt=" + urlEncode(CashBackAmt));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/ProcessDebitCard", postData, timeout, verbose);
    return new Response(responseData);
 }

/**
 * Process ePayment EBT Card Transactions. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - FoodStampSale
 * | FoodStampReturn | CashBenefitSale | Capture | CaptureAll, <BR>CardNum
 * - Payment Card Number, ExpDate - Payment Card Expiration Date in MMYY
 * format, <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard
 * - Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>Pin -
 * Pin Returned by Pin-Pad, <BR>RegisterNum - Register Number Pin-Pad
 * is Connected, <BR>SureChargeAmt - Sure Charge Amount in DDDDD.CC format,
 * <BR>CashBackAmt - Cash Back Amount in DDDDD.CC format, <BR>ExtData
 * - Extended Data in XML, Valid Values are: <BR>Timeout - Timeout Value
 * in Seconds (default=40), <BR>TrainingMode - Training Mode T or F,
 * <BR>KeySerialNumber - Key Serial Number for DUKPT<BR>
 */
synchronized public Response processEBTCard(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String CardNum, java.lang.String ExpDate, java.lang.String MagData, java.lang.String NameOnCard, java.lang.String Amount, java.lang.String InvNum, java.lang.String PNRef, java.lang.String Pin, java.lang.String RegisterNum, java.lang.String SureChargeAmt, java.lang.String CashBackAmt, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&TransType=" + urlEncode(TransType));
    sb.append("&CardNum=" + urlEncode(CardNum));
    sb.append("&ExpDate=" + urlEncode(ExpDate));
    sb.append("&MagData=" + urlEncode(MagData));
    sb.append("&NameOnCard=" + urlEncode(NameOnCard));
    sb.append("&Amount=" + urlEncode(Amount));
    sb.append("&InvNum=" + urlEncode(InvNum));
    sb.append("&PNRef=" + urlEncode(PNRef));
    sb.append("&Pin=" + urlEncode(Pin));
    sb.append("&RegisterNum=" + urlEncode(RegisterNum));
    sb.append("&SureChargeAmt=" + urlEncode(SureChargeAmt));
    sb.append("&CashBackAmt=" + urlEncode(CashBackAmt));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/ProcessEBTCard", postData, timeout, verbose);
    return new Response(responseData);
 }

/**
 * Process ePayment Gift Card Transaction. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - Activate
 * | Deactivate | Refund | Redeem | Inquire | Reload, <BR>CardNum - Payment
 * Card Number, ExpDate - Payment Card Expiration Date in MMYY format,
 * <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard -
 * Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>InvNum -
 * Invoice Tracking Number, PNRef - Reference Number Assigned by the
 * payment gateway, <BR>ExtData - Extended Data in XML, Valid Values
 * are: <BR>Timeout - Timeout Value in Seconds (default=40), <BR>TrainingMode
 * - Training Mode T or F, <BR>Force - Force Duplicates T or F, <BR>
 */
synchronized public Response processGiftCard(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String CardNum, java.lang.String ExpDate, java.lang.String MagData, java.lang.String Amount, java.lang.String InvNum, java.lang.String PNRef, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&TransType=" + urlEncode(TransType));
    sb.append("&CardNum=" + urlEncode(CardNum));
    sb.append("&ExpDate=" + urlEncode(ExpDate));
    sb.append("&MagData=" + urlEncode(MagData));
    sb.append("&Amount=" + urlEncode(Amount));
    sb.append("&InvNum=" + urlEncode(InvNum));
    sb.append("&PNRef=" + urlEncode(PNRef));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/ProcessGiftCard", postData, timeout, verbose);
    return new Response(responseData);
 }

/**
 * Process ePayment Check Transactions. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - Auth
 * | Sale | Return | Force | Void | Capture | CaptureAll, <BR>CheckNum
 * - Check Number, TransitNum - Transit NUmber <BR>AccountNum - AccountNumber,
 * <BR>Amount - Amount in DDDDD.CC format, <BR>MICR - MICR, <BR>NameOnCheck
 * - NameOnCheck, <BR>DL - Drivers License, <BR>SS - Social Security,
 * <BR>StateCode - State Code of the Driver License, <BR>CheckType -
 * CheckType (Personal | Corporate | Government), <BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>Timeout - Timeout Value in Seconds
 * (default=40), <BR>PNRef - Reference Number Assigned by the payment
 * gateway, <BR>Phone - Phone Number, <BR>EMail - E-Mail Address, <BR>RawMICR
 * - Check RawMICR Data, <BR>InvNum - Invoice Number, <BR>TrainingMode
 * - Training Mode T or F, <BR>AccountType - Account Type (Saving | Checking),
 * <BR>CityOfAccount - City where the bank account is located, <BR>BillToStreet
 * - Street address of the billing address, <BR>BillToCity - City of
 * the billing address, <BR>BillToState - State/Province of the billing
 * address, <BR>BillToPostalCode - Zip/Postal Code of the billing address,
 * <BR>BillToCountry - Country of the billing address<BR>
 */
synchronized public Response processCheck(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String CheckNum, java.lang.String TransitNum, java.lang.String AccountNum, java.lang.String Amount, java.lang.String MICR, java.lang.String NameOnCheck, java.lang.String DL, java.lang.String SS, java.lang.String DOB, java.lang.String StateCode, java.lang.String CheckType, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&TransType=" + urlEncode(TransType));
    sb.append("&CheckNum=" + urlEncode(CheckNum));
    sb.append("&TransitNum=" + urlEncode(TransitNum));
    sb.append("&AccountNum=" + urlEncode(AccountNum));
    sb.append("&Amount=" + urlEncode(Amount));
    sb.append("&MICR=" + urlEncode(MICR));
    sb.append("&NameOnCheck=" + urlEncode(NameOnCheck));
    sb.append("&DL=" + urlEncode(DL));
    sb.append("&SS=" + urlEncode(SS));
    sb.append("&DOB=" + urlEncode(DOB));
    sb.append("&StateCode=" + urlEncode(StateCode));
    sb.append("&CheckType=" + urlEncode(CheckType));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/ProcessCheck", postData, timeout, verbose);
    return new Response(responseData);
 }

/**
 * Retrieves information from the Web Service. Valid input values are:
 * UserName & Password - Assigned by the payment gateway, TransType -
 * Initialize | Setup | BatchInquiry | StatusCheck,  <BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>TrainingMode - Training Mode T
 * or F<BR>
 */
synchronized public Response getInfo(java.lang.String UserName, java.lang.String Password, java.lang.String TransType, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&TransType=" + urlEncode(TransType));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/GetInfo", postData, timeout, verbose);
    return new Response(responseData);
 }

/**
 * Process Signature Transaction. <BR>Valid input values are: UserName
 * & Password - Assigned by the payment gateway<BR>SignatureType - Signature1
 * for Lipman credit, Signature2 for Lipman Check, Signature3 for AppForge,
 * Signature4 for app other than AppForge, Receipt1 for TIFF file<BR>SignatureData
 * - an array of coordinate in the following format: x1,y1^x2,y2^x3,y3^...xn,yn^~<BR>Use
 * 0,65535 as the x,y coordinate for any pen-up event.<BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>TrainingMode - Training Mode T
 * or F<BR>
 */
synchronized public Response processSignature(java.lang.String UserName, java.lang.String Password, java.lang.String SignatureType, java.lang.String SignatureData, java.lang.String PNRef, java.lang.String Result, java.lang.String AuthCode, java.lang.String ExtData) throws java.io.IOException {
    java.lang.StringBuffer sb = new StringBuffer();
    sb.append("UserName=" + urlEncode(UserName));
    sb.append("&Password=" + urlEncode(Password));
    sb.append("&SignatureType=" + urlEncode(SignatureType));
    sb.append("&SignatureData=" + urlEncode(SignatureData));
    sb.append("&PNRef=" + urlEncode(PNRef));
    sb.append("&Result=" + urlEncode(Result));
    sb.append("&AuthCode=" + urlEncode(AuthCode));
    sb.append("&ExtData=" + urlEncode(ExtData));
    String postData = sb.toString();
    String responseData = Util.sendHttpPost(url + "/ProcessSignature", postData, timeout, verbose);
    return new Response(responseData);
 }

}
